$world_info = {'host' => '127.0.0.1', 'port' => 4010}

#;e Map.area.set_start(Map.current.num)

Char.add_vars('prompt', 'held', 'dual')

##### WINDOW CREATION #####
$app.add_box('chat', /\{chan ch=\w+?\}/, false, true)
$app.set_add_box_get('chat', Proc.new {|text|
  text = text.gsub(/\{chan ch=.+?\}/, '')
})
$app.add_box('map', /<MAPSTART>.+?<MAPEND>/m, false, false, true)

def cp_hunt_string(id); "\x1B[98mHUNT-#{id}\x1B[0m" end
def go2_string(*rooms); "\x1B[99m#{rooms.join("\x1B[0m, \x1B[99m")}\x1B[0m" end
def go2(id, sleep_length = 0, wait = true)
  start_script('go2', id)
  wait_while {running?('go2')} if wait
  sleep(sleep_length) if sleep_length > 0
end
def go2p(id, sleep_length = 0, wait = true)
  start_script('go2_proc', id)
  wait_while {running?('go2_proc')} if wait
  sleep(sleep_length) if sleep_length > 0
end

RubyMudColors.add_override('98', 'cp_hunt_link 36base u')
RubyMudColors.add_override('99', 'go2link 34bold u')
$app.show_box.tag_bind('go2link', '1', Proc.new {|e| start_script('go2', e.widget.get(*e.widget.tag_nextrange('go2link', 'current wordstar')))})
$app.add_boxes['chat'].text.tag_bind('go2link', '1', Proc.new {|e| start_script('go2', e.widget.get(*e.widget.tag_nextrange('go2link', 'current wordstar')))})
$app.add_boxes['chat'].text.tag_bind('cp_hunt_link', '1', Proc.new {|e| hunt_cp(e.widget.get(*e.widget.tag_nextrange('cp_hunt_link', 'current wordstar')))})
$app.add_boxes['chat'].text.bind('Key') {|e| $app.type_box.focus;$app.type_box.event_generate(e.keysym);break}

dh_mapping, dh_map = false, ''
DownstreamHook.remove('map')
DownstreamHook.add('map', Proc.new {|cs|
  dh_mapping ||= cs.clean_colors =~ /<MAPSTART>/
  if dh_mapping
    if cs.clean_colors !~ /<MAP(START|END)>/
      dh_map += cs unless cs.clean_colors.strip.length == 0 || cs.clean_colors =~ /^(?:\w|\[)/i
    elsif cs.clean_colors =~ /MAPEND/
      $app.add_boxes['map'].display_text(dh_map)
      dh_mapping, dh_map = false, ''
    end
    nil
  else
    cs
  end
})

DownstreamHook.remove('replacements')
DownstreamHook.add('replacements', Proc.new {|cs|
  cs.gsub!(/\{rname\}/, "[#{Map.rev_mapping(Room.current.db_id)}-#{Room.current.area.num}] ")
  cs.gsub(/\{chan ch=.+?\}/, '')
})

Map.add_id_mapping({
  'recall' => 32418,
  'quest' => 32458,
  'fountain' => 35233,
  'train' => 35203,
  'prac' => 35204,
  'pot' => 32476,
  'cp' => 32614
})

$plane_rooms = {
  'Gladsheim' => 236,
  'Pandemoniom' => 251,
  'Hades' => 266,
  'Gehenna' => 281,
  'Acheron' => 301,
  'Twin Paradises' => 10870,
  'Arcadia' => 10820,
  'Seven Heavens' => 10835,
  'Elysium' => 10890,
  'Beastlands' => 10910
}

$map_loaded ||= false
Map.init unless $map_loaded
$map_loaded = true